package com.zhenwei.zscm.common.base;

import com.zhenwei.zscm.model.dto.user.UserDTO;
import com.zhenwei.zscm.model.enums.RoleEnum;

public class UserContext {
    private static final ThreadLocal<UserDTO> CURRENT_USER = new ThreadLocal<>();

    public static void setCurrentUser(UserDTO userInfo) {
        CURRENT_USER.set(userInfo);
    }

    public static UserDTO getCurrentUser() {
        return CURRENT_USER.get();
    }
    public static boolean isAdmin(){
        return RoleEnum.ADMIN.name().equals(getCurrentUser().getRole());
    }
    public static boolean isNotAdmin(){
        return !RoleEnum.ADMIN.name().equals(getCurrentUser().getRole());
    }
    public static void clear() {
        CURRENT_USER.remove();
    }
}
